package com.hwadee.springboot_lx.entity;

import lombok.Getter;
import lombok.Setter;

import java.time.LocalDateTime;

@Setter
@Getter
public class Log {
    // Getter 和 Setter 方法
    private Long id;
    private String logType;
    private String details;
    private LocalDateTime time;
    private String operator;

    @Override
    public String toString() {
        return "Log{" +
                "id=" + id +
                ", logType='" + logType + '\'' +
                ", details='" + details + '\'' +
                ", time=" + time +
                ", operator='" + operator + '\'' +
                '}';
    }

    public boolean matches(LogSearchCriteria criteria) {
        boolean matchesTime = (criteria.getStartDate() == null || !time.isBefore(criteria.getStartDate())) &&
                (criteria.getEndDate() == null || !time.isAfter(criteria.getEndDate()));
        boolean matchesType = (criteria.getLogType() == null || logType.equals(criteria.getLogType()));
        boolean matchesQuery = (criteria.getSearchQuery() == null || details.contains(criteria.getSearchQuery()));

        return matchesTime && matchesType && matchesQuery;
    }
}

